---@class RedDotsExpeditionSweepHandler
RedDotsDebrisHandler ={};
local this = RedDotsDebrisHandler;

function RedDotsDebrisHandler.init()
    CloseEvent(Config.EventType.DebrisUpdate,this.update);
    ListenEvent(Config.EventType.DebrisUpdate,this.update);
    return this;
end

--
function RedDotsDebrisHandler.getFlag(chip)
    -- if type(chip) == "string" then
    --     chip = logicMgr.StrangeFragmentManager.GetCurrentEquipFragment(chip)
    -- end

    local flag = Config.RedDotsFlagState.None;
    -- if logicMgr.StrangeFragmentManager.CheckTheChipUpgrade(chip) then
    --     flag = Config.RedDotsFlagState.Needful
    -- end
    return flag
end

function RedDotsDebrisHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.debrisUpgrade)
end


RedDotsDebrisChangeHandler ={};

function RedDotsDebrisChangeHandler.init()
    CloseEvent(Config.EventType.DebrisUpdate,RedDotsDebrisChangeHandler.update)
    CloseEvent(Config.EventType.Fragment_Unwear,RedDotsDebrisChangeHandler.update)
    CloseEvent(Config.EventType.Fragment_Wear,RedDotsDebrisChangeHandler.update)
    ListenEvent(Config.EventType.DebrisUpdate,RedDotsDebrisChangeHandler.update)
    ListenEvent(Config.EventType.Fragment_Wear,RedDotsDebrisChangeHandler.update)
    ListenEvent(Config.EventType.Fragment_Unwear,RedDotsDebrisChangeHandler.update)
    return RedDotsDebrisChangeHandler
end

--
function RedDotsDebrisChangeHandler.getFlag(chip)
    if type(chip) == "string" then
        local hero = logicMgr.HeroManager.getHeroDatabyPartnerId(chip,true)
        if hero.level == 1 then
            return Config.RedDotsFlagState.None
        end

        if logicMgr.FuncOpenManager.isOpen(Config.FuncOpenType.WeaponRefine, false, nil, { heroId = chip }) then
            chip = logicMgr.StrangeFragmentManager.GetCurrentEquipFragment(chip)
        end
    end
    local flag = Config.RedDotsFlagState.None;
    if logicMgr.StrangeFragmentManager.CheckTheChipChangeCondition(chip) then
        flag = Config.RedDotsFlagState.Needful
    end
    return flag
end

function RedDotsDebrisChangeHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.debrisChange)
end

--- 魂石突破红点逻辑
RedDotsDebrisBrokenHandler ={};
local this = RedDotsDebrisBrokenHandler;

function RedDotsDebrisBrokenHandler.init()
    CloseEvent(Config.EventType.DebrisBroken,  this.update);
    ListenEvent(Config.EventType.DebrisBroken, this.update);
    return this;
end

--
function RedDotsDebrisBrokenHandler.getFlag(chip)
    if type(chip) == "string" then
        chip = logicMgr.StrangeFragmentManager.GetCurrentEquipFragment(chip)
    end
    
    local flag = Config.RedDotsFlagState.None
    if logicMgr.StrangeFragmentManager.CheckTheChipBroken(chip) then
        flag = Config.RedDotsFlagState.Needful
    end
    return flag
end

function RedDotsDebrisBrokenHandler.update()
    RedDotsManager.addBroadcast(Config.RedDotsType.debrisBroken)
end